home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / bstfiles.zoo / xbtxbst.doc < prev   
Text File  |  1991-09-12  |  78KB  |  2,666 lines

  1. % /u/sy/beebe/tex/bib/merge/xbtxbst.doc, Thu Sep 12 10:19:13 1991
  2. % Edit by Nelson H. F. Beebe <beebe@magna.math.utah.edu>
  3. % /u/sy/beebe/tex/bib/merge/xbtxbst.doc, Wed Oct 17 08:27:24 1990
  4. % Edit by Nelson H.F. Beebe <beebe@sandy.math.utah.edu>
  5.  
  6. % NB: Important convention: comment lines beginning with 2 (or
  7. %     more) percents are to be preserved in the derived style
  8. %     files.   Comment lines beginning with only 1 percent can be
  9. %     discarded (and are, if the derived files are produced with
  10. %     the UNIX Makefile that accompanies this file.)
  11.  
  12. %% =====================================================================
  13. %%  @BibTeX-style-file{
  14. %%      author          = "Nelson H. F. Beebe",
  15. %%      version         = "1.02",
  16. %%      date            = "12 September 1991",
  17. %%      filename        = "xbtxbst.doc",
  18. %%      address         = "Center for Scientific Computing
  19. %%                         Department of Mathematics
  20. %%                         South Physics Building
  21. %%                         University of Utah
  22. %%                         Salt Lake City, UT 84112
  23. %%                         USA
  24. %%                         Tel: (801) 581-5254",
  25. %%      checksum        = "50938 2665 11236 78415",
  26. %%      email           = "beebe@math.utah.edu (Internet)",
  27. %%      codetable       = "ISO/ASCII",
  28. %%      keywords        = "BibTeX, style, bibliography",
  29. %%      supported       = "yes",
  30. %%      docstring       = "This file is a modification of the standard
  31. %%                         BibTeX btxbst.doc file, or is a .bst file
  32. %%                         derived from that modification.  It contains
  33. %%                         added support for ISBN and ISSN fields, as
  34. %%                         well as for the PERIODICAL entry.  The UNIX C
  35. %%                         preprocessor can be used to extract the
  36. %%                         extensions of the standard styles, as
  37. %%                         follows:
  38. %%
  39. %%                         cpp -P -DPLAIN xbtxbst.doc is-plain.txt
  40. %%                         cpp -P -DUNSRT xbtxbst.doc is-unsrt.txt
  41. %%                         cpp -P -DALPHA xbtxbst.doc is-alpha.txt
  42. %%                         cpp -P -DABBRV xbtxbst.doc is-abbrv.txt
  43. %%
  44. %%                         If desired, a sed script can be used to
  45. %%                         eliminate non-essential comments (this
  46. %%                         reduces the file size by 2/3); a command
  47. %%                         filter step like
  48. %%                                 sed -e '/^%$/d' -e '/^%[^%].*$/d'
  49. %%                         will accomplish that job.
  50. %%
  51. %%                         The checksum field above contains a CRC-16
  52. %%                         checksum as the first value, followed by the
  53. %%                         equivalent of the standard UNIX wc (word
  54. %%                         count) utility output of lines, words, and
  55. %%                         characters.  This is produced by Robert
  56. %%                         Solovay's checksum utility."
  57. %%      }
  58. %% =====================================================================
  59. %% Revision history (reverse time order):
  60. %% 1.02 [12-Sep-1991]
  61. %%      Merge in Barbara N. Beeton's suggestion for hyphen-less
  62. %%      line breaks around volume(number):page.
  63. %% 1.01 [10-Sep-1991]
  64. %%      Update file comment header and use Solovay checksum program.
  65. %% 1.00 [17-Oct-1990]
  66. %%      Original version merging hand-edits of is-xxx.bst files into
  67. %%      this master file, xbtxbst.doc.
  68.  
  69. % In the following, only essential changes have been applied; the
  70. % documentation immediately below referring to the use of cpp on
  71. % btxbst.doc has not been altered.  See the docstring entry above
  72. % for current information.
  73.  
  74. %% BibTeX `plain' family
  75. %%       version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  76. %%       Copyright (C) 1985, all rights reserved.
  77. %%       Copying of this file is authorized only if either
  78. %%       (1) you make absolutely no changes to your copy, including name, or
  79. %%       (2) if you do make changes, you name it something other than
  80. %%       btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  81. %%       This restriction helps ensure that all standard styles are identical.
  82. %%       The file btxbst.doc has the documentation for this style.
  83. %
  84. % Please notify Oren Patashnik (PATASHNIK@SCORE.STANFORD.EDU) of any bugs in
  85. % these standard styles or in this documentation file.
  86. %
  87. % This is file btxbxt.doc; it helps document bibliography styles,
  88. % and is also a template file that you can use to make
  89. % several different style files, if you have access to a C preprocessor.
  90. % For example, the standard styles were made by doing something like
  91. %       cpp -P -DPLAIN btxbst.doc plain.txt
  92. %       cpp -P -DUNSRT btxbst.doc unsrt.txt
  93. %       cpp -P -DALPHA btxbst.doc alpha.txt
  94. %       cpp -P -DABBRV btxbst.doc abbrv.txt
  95. % and then renaming after removing unwanted comments and blank lines.
  96. % If you don't have access,
  97. % you can edit this file by hand to imitate the preprocessor,
  98. % with the following explanation of the C preprocessor constructs used here.
  99. %
  100. % The output of the preprocessor is the same as the input, except that certain
  101. % lines will be excluded (and some blank lines will be added).  The sequence
  102. %       #if VAR
  103. %           lines to be included when VAR is not zero
  104. %       #else
  105. %           lines to be included when VAR is zero
  106. %       #endif
  107. % (with the #-signs appearing in column 1) means that one set or the other of
  108. % the lines are to be included depending on the value of VAR.
  109. % The #else part is optional.  Comments can be added after #else and #endif.
  110. % Variables can be set by
  111. %       #define VAR value
  112. % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
  113. % to see if it has none.
  114. % Another #if form used in this file is #if !VAR, which includes the lines
  115. % after the #if only if VAR is zero.
  116. %
  117. % Convention: Use all uppercase identifiers for these preprocessor variables
  118. % so you can spot them easily
  119. %
  120. % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
  121. % or ABBRV (though PLAIN will be used by default if none is given),
  122. % and the following lines will set various boolean variables to control the
  123. % various lines that are chosen from the rest of the file.
  124. % Each boolean variable should be set true (1) or false (0) in each style.
  125. % Here are the current variables, and their meanings:
  126. %       LAB_ALPH:       an alphabetic label is used (if false then a numeric
  127. %                           label is used)
  128. %       SORTED:         the entries should be sorted by label (if nonnumeric)
  129. %                           and other info, like authors (if false, then
  130. %                           entries remain in order of occurrence)
  131. %       NAME_FULL:      the authors, editors, etc., get the full names as
  132. %                           given in the bibliography file (if false, the first
  133. %                           names become initials)
  134. %       ATIT_LOWER:     titles of non-"books" (e.g., articles) should be
  135. %                           converted to lower-case, except the first letter or
  136. %                           first letter after a colon
  137. %                           (if false then they appear as in the database)
  138. %       MONTH_FULL:     months are spelled out in full (if false, then
  139. %                           they're abbreviated)
  140. %       JOUR_FULL:      macro journal names are spelled out in full
  141. %                           (if false then they are abbreviated, currently
  142. %                           as they appear in ACM publications)
  143. #ifndef UNSRT
  144. #   ifndef ALPHA
  145. #       ifndef ABBRV
  146. #           define PLAIN 1
  147. #       endif
  148. #   endif
  149. #endif
  150. #ifdef PLAIN
  151. % plain style (sorted numbers)
  152. #   define LAB_ALPH 0
  153. #   define SORTED 1
  154. #   define NAME_FULL 1
  155. #   define ATIT_LOWER 1
  156. #   define MONTH_FULL 1
  157. #   define JOUR_FULL 1
  158. #endif
  159. #ifdef UNSRT
  160. % unsrt style (unsorted numbers)
  161. #   define LAB_ALPH 0
  162. #   define SORTED 0
  163. #   define NAME_FULL 1
  164. #   define ATIT_LOWER 1
  165. #   define MONTH_FULL 1
  166. #   define JOUR_FULL 1
  167. #endif
  168. #ifdef ALPHA
  169. % alpha style (sorted short alphabetics)
  170. #   define LAB_ALPH 1
  171. #   define SORTED 1
  172. #   define NAME_FULL 1
  173. #   define ATIT_LOWER 1
  174. #   define MONTH_FULL 1
  175. #   define JOUR_FULL 1
  176. #endif
  177. #ifdef ABBRV
  178. % abbrv style (sorted numbers, with abbreviations)
  179. #   define LAB_ALPH 0
  180. #   define SORTED 1
  181. #   define NAME_FULL 0
  182. #   define ATIT_LOWER 1
  183. #   define MONTH_FULL 0
  184. #   define JOUR_FULL 0
  185. #endif
  186. %
  187. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  188. %       in "A Handbook for Scholars".  Book-like titles are italicized
  189. %       (emphasized) and non-book titles are converted to sentence
  190. %       capitilization (and not enclosed in quotes).
  191. %       This file outputs a \newblock between major blocks of an entry
  192. %       (the name \newblock is analogous to the names \newline and \newpage)
  193. %       so that the user can obtain an "open" format, which has a line break
  194. %       before each block and lines after the first are indented within blocks,
  195. %       by giving the optional \documentstyle argument `openbib';
  196. %       The default is the "closed" format---blocks runs together.
  197. %
  198. %   Citation alphabetic label format:
  199. %               [Knu73] for single author (or editor or key)
  200. %               [AHU83] (first letters of last names) for multiple authors
  201. %
  202. %   Citation label numberic format:
  203. %               [number]
  204. %
  205. %   Reference list ordering for sorted, alphabetic lables:
  206. %               alphabetical by citation label, then by author(s) or whatever
  207. %               passes for author in the absence of one, then by year,
  208. %               then title
  209. %
  210. %   Reference list ordering for sorted, numeric lables:
  211. %               alphabetical by author(s) or whatever passes
  212. %               for author in the absence of one, then by year, then title
  213. %
  214. %   Reference list ordering for unsorted:
  215. %               by the order cited in the text
  216. %
  217. %   History
  218. %   12/16/84    (HWT)   Original `plain' version, by Howard Trickey.
  219. %   12/23/84    (LL)    Some comments made by Leslie Lamport.
  220. %    2/16/85    (OP)    Changes based on LL's comments, Oren Patashnik.
  221. %    2/17/85    (HWT)   Template file and other standard styles made.
  222. %    3/28/85    (OP)    First release, version 0.98b for BibTeX 0.98f.
  223. %    5/ 9/85    (OP)    Version 0.98c for BibTeX 0.98i:
  224. %                       fixed Theoretical Computer Science macro name;
  225. %                       fixed the format.vol.num.pages function.
  226. %    1/24/88    (OP)    Version 0.99a for BibTeX 0.99a, main changes:
  227. %                       assignment operator (:=) arguments reversed;
  228. %                       the preamble$ function outputs the database PREAMBLE;
  229. %                       entry.max$ and global.max$ (built-in) variables replace
  230. %                       entry.string.max and global.string.max functions;
  231. %                       alphabetizing by year then title, not just title;
  232. %                       many unnecessary ties removed; \it ==> \em;
  233. %                       the `alpha' style uses a superscripted `+' instead of a
  234. %                       `*' for unnamed names in constructing the label;
  235. %                       the `abbrv' style now uses "Mar." and "Sept.";
  236. %                       the functions calc.label and presort now look at just
  237. %                       the fields they're supposed to;
  238. %                       BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
  239. %                       INBOOK and INCOLLECTION take an optional type (e.g.
  240. %                       type = "Section"), overriding the default "chapter";
  241. %                       BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
  242. %                       either volume or number, not just volume;
  243. %                       INCOLLECTION now allows an edition and series field;
  244. %                       PROCEEDINGS and INPROCEEDINGS now use the address field
  245. %                       to tell where a conference was held;
  246. %                       INPROCEEDINGS and PROCEEDINGS now allow either volume
  247. %                       or number, and also a series field;
  248. %                       MASTERSTHESIS and PHDTHESIS accept types other than
  249. %                       "Master's thesis" and "PhD thesis";
  250. %                       UNPUBLISHED now outputs, in one block, note then date;
  251. %                       MANUAL now prints out the organization in
  252. %                       the first block if the author field is empty;
  253. %                       MISC can't be empty---it requires some optional field.
  254. %    3/23/88    (OP)    Version 0.99b for BibTeX 0.99c---changed the three
  255. %                       erroneous occurrences of `cite ' to `cite$ '; this
  256. %                       change didn't affect the four standard styles, so the
  257. %                       0.99a versions of those styles are still current.
  258. %
  259. % The ENTRY declaration
  260. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  261. %   but no fullauthor or editors fields because BibTeX does name handling.
  262. %   The annote field is commented out here because this family doesn't
  263. %   include an annotated bibliography style.  And in addition to the fields
  264. %   listed here, BibTeX has a built-in crossref field, explained later.
  265.  
  266. ENTRY
  267. % Fields:
  268.   { address
  269. %           Usually the address of a publisher or other type of organization.
  270. %           Put information in this field only if it helps the reader find the
  271. %           thing---for example you should omit the address of a major
  272. %           publisher entirely.  For a PROCEEDINGS or an INPROCEEDINGS,
  273. %           however, it's the address of the conference; for those two entry
  274. %           types, include the publisher's or organization's address, if
  275. %           necessary, in the publisher or organization field.
  276. %    annote
  277. %           Long annotation---for annotated bibliographies (begins sentence).
  278.     author
  279. %           Name(s) of author(s), in BibTeX name format.
  280.     booktitle
  281. %           Book title when the thing being referenced isn't the whole book.
  282. %           For book entries, the title field should be used instead.
  283.     chapter
  284. %           Chapter (or section or whatever) number.
  285.     edition
  286. %           Edition of a book---should be an ordinal (e.g., "Second").
  287.     editor
  288. %           Name(s) of editor(s), in BibTeX name format.
  289. %           If there is also an author field, then the editor field should be
  290. %           for the book or collection that the work appears in.
  291.     howpublished
  292. %            How something strange has been published (begins sentence).
  293.     institution
  294. %           Sponsoring institution of a technical report.
  295.     isbn
  296. %           ISBN book number (a 10-digit number with optional
  297. %           embedded spaces or hyphens, where a `digit' is one of
  298. %           0123456789X).
  299.     issn
  300. %           ISSN serial publication number (an 8-digit number with optional
  301. %           embedded spaces or hyphens, where a `digit' is one of
  302. %           0123456789X).
  303.     journal
  304. %           Journal name (macros are provided for many).
  305.     key
  306. %           Alphabetizing, labeling, and cross-referencing key
  307. %           (needed when an entry has no author or editor).
  308.     month
  309. %           Month (macros are provided).
  310.     note
  311. %           To help the reader find a reference (begins sentence).
  312.     number
  313. %           Number of a journal or technical report, or of a work in a series.
  314.     organization
  315. %           Organization sponsoring a conference (or publishing a manual); if
  316. %           the editor (or author) is empty, and if the organization produces
  317. %           an awkward label or cross reference, you should put appropriately
  318. %           condensed organization information in the key field as well.
  319.     pages
  320. %           Page number or numbers (use `--' to separate a range, use `+'
  321. %           to indicate pages following that don't form a simple range).
  322.     publisher
  323. %           Publisher name.
  324.     school
  325. %           School name (for theses).
  326.     series
  327. %           The name of a series or set of books.
  328. %           An individual book will will also have it's own title.
  329.     title
  330. %           The title of the thing you're referred to.
  331.     type
  332. %           Type of a Techreport (e.g., "Research Note") to be used instead of
  333. %           the default "Technical Report"; or, similarly, the type of a
  334. %           thesis; or of a part of a book.
  335.     volume
  336. %           The volume number of a journal or multivolume work.
  337.     year
  338. %           The year should contain only numerals (technically, it should end
  339. %           with four numerals, after purification; doesn't a begin sentence).
  340.   }
  341. % There are no integer entry variables
  342.   {}
  343. % These string entry variables are used to form the citation label.
  344. % In a storage pinch, sort.label can be easily computed on the fly.
  345. #if LAB_ALPH
  346. #if SORTED
  347.   { label extra.label sort.label }
  348. #else !SORTED
  349. % It doesn't seem like a good idea to use an order-of-citation
  350. % reference list when using alphabetic labels, but when this happens
  351. % we do things a little differently
  352.   { label }
  353. #endif SORTED
  354. #else !LAB_ALPH
  355.   { label }
  356. #endif LAB_ALPH
  357.  
  358. % Each entry function starts by calling output.bibitem, to write the
  359. % \bibitem and its arguments to the .BBL file.  Then the various fields
  360. % are formatted and printed by output or output.check.  Those functions
  361. % handle the writing of separators (commas, periods, \newblock's),
  362. % taking care not to do so when they are passed a null string.
  363. % Finally, fin.entry is called to add the final period and finish the
  364. % entry.
  365. %
  366. % A bibliographic reference is formatted into a number of `blocks':
  367. % in the open format, a block begins on a new line and subsequent
  368. % lines of the block are indented.  A block may contain more than
  369. % one sentence (well, not a grammatical sentence, but something to
  370. % be ended with a sentence ending period).  The entry functions should
  371. % call new.block whenever a block other than the first is about to be
  372. % started.  They should call new.sentence whenever a new sentence is
  373. % to be started.  The output functions will ensure that if two
  374. % new.sentence's occur without any non-null string being output between
  375. % them then there won't be two periods output.  Similarly for two
  376. % successive new.block's.
  377. %
  378. % The output routines don't write their argument immediately.
  379. % Instead, by convention, that argument is saved on the stack to be
  380. % output next time (when we'll know what separator needs to come
  381. % after it).  Meanwhile, the output routine has to pop the pending
  382. % output off the stack, append any needed separator, and write it.
  383. %
  384. % To tell which separator is needed, we maintain an output.state.
  385. % It will be one of these values:
  386. %       before.all              just after the \bibitem
  387. %       mid.sentence            in the middle of a sentence: comma needed
  388. %                                       if more sentence is output
  389. %       after.sentence          just after a sentence: period needed
  390. %       after.block             just after a block (and sentence):
  391. %                                       period and \newblock needed.
  392. % Note: These styles don't use after.sentence
  393. %
  394. % VAR: output.state : INTEGER           -- state variable for output
  395. %
  396. % The output.nonnull function saves its argument (assumed to be nonnull)
  397. % on the stack, and writes the old saved value followed by any needed
  398. % separator.  The ordering of the tests is decreasing frequency of
  399. % occurrence.
  400. %
  401. % output.nonnull(s) ==
  402. %  BEGIN
  403. %       s := argument on stack
  404. %       if output.state = mid.sentence then
  405. %           write$(pop() * ", ")
  406. %                 -- "pop" isn't a function: just use stack top
  407. %       else
  408. %           if output.state = after.block then
  409. %               write$(add.period$(pop()))
  410. %               newline$
  411. %               write$("\newblock ")
  412. %           else
  413. %               if output.state = before.all then
  414. %                   write$(pop())
  415. %               else        -- output.state should be after.sentence
  416. %                   write$(add.period$(pop()) * " ")
  417. %               fi
  418. %           fi
  419. %           output.state := mid.sentence
  420. %       fi
  421. %       push s on stack
  422. %  END
  423. %
  424. % The output function calls output.nonnull if its argument is non-empty;
  425. % its argument may be a missing field (thus, not necessarily a string)
  426. %
  427. % output(s) ==
  428. %  BEGIN
  429. %       if not empty$(s) then output.nonnull(s)
  430. %       fi
  431. %  END
  432. %
  433. % The output.check function is the same as the output function except that, if
  434. % necessary, output.check warns the user that the t field shouldn't be empty
  435. % (this is because it probably won't be a good reference without the field;
  436. % the entry functions try to make the formatting look reasonable even when
  437. % such fields are empty).
  438. %
  439. % output.check(s,t) ==
  440. %  BEGIN
  441. %       if empty$(s) then
  442. %           warning$("empty " * t * " in " * cite$)
  443. %       else output.nonnull(s)
  444. %       fi
  445. %  END
  446. %
  447. % The output.bibitem function writes the \bibitem for the current entry
  448. % (the label should already have been set up), and sets up the separator
  449. % state for the output functions.  And, it leaves a string on the stack
  450. % as per the output convention.
  451. %
  452. % output.bibitem ==
  453. %  BEGIN
  454. %       newline$
  455. %       write$("\bibitem[")     % for alphabetic labels,
  456. %       write$(label)           % these three lines
  457. %       write$("]{")            % are used
  458. %       write$("\bibitem{")             % this line for numeric labels
  459. %       write$(cite$)
  460. %       write$("}")
  461. %       push "" on stack
  462. %       output.state := before.all
  463. %  END
  464. %
  465. % The fin.entry function finishes off an entry by adding a period to the
  466. % string remaining on the stack.  If the state is still before.all
  467. % then nothing was produced for this entry, so the result will look bad,
  468. % but the user deserves it. (We don't omit the whole entry because the
  469. % entry was cited, and a bibitem is needed to define the citation label.)
  470. %
  471. % fin.entry ==
  472. %  BEGIN
  473. %       write$(add.period$(pop()))
  474. %       newline$
  475. %  END
  476. %
  477. % The new.block function prepares for a new block to be output, and
  478. % new.sentence prepares for a new sentence.
  479. %
  480. % new.block ==
  481. %  BEGIN
  482. %       if output.state <> before.all then
  483. %           output.state := after.block
  484. %       fi
  485. %  END
  486. %
  487. % new.sentence ==
  488. %  BEGIN
  489. %       if output.state <> after.block then
  490. %           if output.state <> before.all then
  491. %               output.state :=  after.sentence
  492. %           fi
  493. %       fi
  494. %  END
  495. %
  496.  
  497. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  498.  
  499. FUNCTION {init.state.consts}
  500. { #0 'before.all :=
  501.   #1 'mid.sentence :=
  502.   #2 'after.sentence :=
  503.   #3 'after.block :=
  504. }
  505.  
  506. % the variables s and t are temporary string holders
  507.  
  508. STRINGS { s t }
  509.  
  510. FUNCTION {output.nonnull}
  511. { 's :=
  512.   output.state mid.sentence =
  513.     { ", " * write$ }
  514.     { output.state after.block =
  515.         { add.period$ write$
  516.           newline$
  517.           "\newblock " write$
  518.         }
  519.         { output.state before.all =
  520.             'write$
  521.             { add.period$ " " * write$ }
  522.           if$
  523.         }
  524.       if$
  525.       mid.sentence 'output.state :=
  526.     }
  527.   if$
  528.   s
  529. }
  530.  
  531. FUNCTION {output}
  532. { duplicate$ empty$
  533.     'pop$
  534.     'output.nonnull
  535.   if$
  536. }
  537.  
  538. FUNCTION {output.check}
  539. { 't :=
  540.   duplicate$ empty$
  541.     { pop$ "empty " t * " in " * cite$ * warning$ }
  542.     'output.nonnull
  543.   if$
  544. }
  545.  
  546. FUNCTION {output.bibitem}
  547. { newline$
  548. #if LAB_ALPH
  549.   "\bibitem[" write$
  550.   label write$
  551.   "]{" write$
  552. #else
  553.   "\bibitem{" write$
  554. #endif LAB_ALPH
  555.   cite$ write$
  556.   "}" write$
  557.   newline$
  558.   ""
  559.   before.all 'output.state :=
  560. }
  561.  
  562. % This function finishes all entries.
  563.  
  564. FUNCTION {fin.entry}
  565. { add.period$
  566.   write$
  567.   newline$
  568. }
  569.  
  570. FUNCTION {new.block}
  571. { output.state before.all =
  572.     'skip$
  573.     { after.block 'output.state := }
  574.   if$
  575. }
  576.  
  577. FUNCTION {new.sentence}
  578. { output.state after.block =
  579.     'skip$
  580.     { output.state before.all =
  581.         'skip$
  582.         { after.sentence 'output.state := }
  583.       if$
  584.     }
  585.   if$
  586. }
  587.  
  588. % These three functions pop one or two (integer) arguments from the stack
  589. % and push a single one, either 0 or 1.
  590. % The 'skip$ in the `and' and `or' functions are used because
  591. % the corresponding if$ would be idempotent
  592.  
  593. FUNCTION {not}
  594. {   { #0 }
  595.     { #1 }
  596.   if$
  597. }
  598.  
  599. FUNCTION {and}
  600. {   'skip$
  601.     { pop$ #0 }
  602.   if$
  603. }
  604.  
  605. FUNCTION {or}
  606. {   { pop$ #1 }
  607.     'skip$
  608.   if$
  609. }
  610.  
  611. % Sometimes we begin a new block only if the block will be big enough.  The
  612. % new.block.checka function issues a new.block if its argument is nonempty;
  613. % new.block.checkb does the same if either of its TWO arguments is nonempty.
  614.  
  615. FUNCTION {new.block.checka}
  616. { empty$
  617.     'skip$
  618.     'new.block
  619.   if$
  620. }
  621.  
  622. FUNCTION {new.block.checkb}
  623. { empty$
  624.   swap$ empty$
  625.   and
  626.     'skip$
  627.     'new.block
  628.   if$
  629. }
  630.  
  631. % The new.sentence.check functions are analogous.
  632.  
  633. FUNCTION {new.sentence.checka}
  634. { empty$
  635.     'skip$
  636.     'new.sentence
  637.   if$
  638. }
  639.  
  640. FUNCTION {new.sentence.checkb}
  641. { empty$
  642.   swap$ empty$
  643.   and
  644.     'skip$
  645.     'new.sentence
  646.   if$
  647. }
  648.  
  649. % Here are some functions for formatting chunks of an entry.
  650. % By convention they either produce a string that can be followed by
  651. % a comma or period (using add.period$, so it is OK to end in a period),
  652. % or they produce the null string.
  653. %
  654. % A useful utility is the field.or.null function, which checks if the
  655. % argument is the result of pushing a `missing' field (one for which no
  656. % assignment was made when the current entry was read in from the database)
  657. % or the result of pushing a string having no non-white-space characters.
  658. % It returns the null string if so, otherwise it returns the field string.
  659. % Its main (but not only) purpose is to guarantee that what's left on the
  660. % stack is a string rather than a missing field.
  661. %
  662. % field.or.null(s) ==
  663. %  BEGIN
  664. %       if empty$(s) then return ""
  665. %       else return s
  666. %  END
  667. %
  668. % Another helper function is emphasize, which returns the argument emphazised,
  669. % if that is non-empty, otherwise it returns the null string.  Italic
  670. % corrections aren't used, so this function should be used when punctation
  671. % will follow the result.
  672. %
  673. % emphasize(s) ==
  674. %  BEGIN
  675. %       if empty$(s) then return ""
  676. %       else return "{\em " * s * "}"
  677. %
  678. % The format.names function formats the argument (which should be in
  679. % BibTeX name format) into "First Von Last, Junior", separated by commas
  680. % and with an "and" before the last (but ending with "et~al." if the last
  681. % of multiple authors is "others").  This function's argument should always
  682. % contain at least one name.
  683. %
  684. % VAR: nameptr, namesleft, numnames: INTEGER
  685. % pseudoVAR: nameresult: STRING         (it's what's accumulated on the stack)
  686. %
  687. % format.names(s) ==
  688. %  BEGIN
  689. %       nameptr := 1
  690. %       numnames := num.names$(s)
  691. %       namesleft := numnames
  692. %       while namesleft > 0
  693. %         do
  694. %                               % for full names:
  695. %           t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  696. %                               % for abbreviated first names:
  697. %           t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  698. %           if nameptr > 1 then
  699. %               if namesleft > 1 then nameresult := nameresult * ", " * t
  700. %               else if numnames > 2
  701. %                      then nameresult := nameresult * ","
  702. %                    fi
  703. %                    if t = "others"
  704. %                      then nameresult := nameresult * " et~al."
  705. %                      else nameresult := nameresult * " and " * t
  706. %                    fi
  707. %               fi
  708. %           else nameresult := t
  709. %           fi
  710. %           nameptr := nameptr + 1
  711. %           namesleft := namesleft - 1
  712. %         od
  713. %       return nameresult
  714. %  END
  715. %
  716. % The format.authors function returns the result of format.names(author)
  717. % if the author is present, or else it returns the null string
  718. %
  719. % format.authors ==
  720. %  BEGIN
  721. %       if empty$(author) then return ""
  722. %       else return format.names(author)
  723. %       fi
  724. %  END
  725. %
  726. % Format.editors is like format.authors, but it uses the editor field,
  727. % and appends ", editor" or ", editors"
  728. %
  729. % format.editors ==
  730. %  BEGIN
  731. %       if empty$(editor) then return ""
  732. %       else
  733. %           if num.names$(editor) > 1 then
  734. %               return format.names(editor) * ", editors"
  735. %           else
  736. %               return format.names(editor) * ", editor"
  737. %           fi
  738. %       fi
  739. %  END
  740. %
  741. % Other formatting functions are similar, so no "comment version" will be
  742. % given for them.
  743. %
  744. % The `pop$' in this function gets rid of the duplicate `empty' value and
  745. % the `skip$' returns the duplicate field value
  746.  
  747. FUNCTION {field.or.null}
  748. { duplicate$ empty$
  749.     { pop$ "" }
  750.     'skip$
  751.   if$
  752. }
  753.  
  754. FUNCTION {emphasize}
  755. { duplicate$ empty$
  756.     { pop$ "" }
  757.     { "{\em " swap$ * "}" * }
  758.   if$
  759. }
  760.  
  761. INTEGERS { nameptr namesleft numnames }
  762.  
  763. FUNCTION {format.names}
  764. { 's :=
  765.   #1 'nameptr :=
  766.   s num.names$ 'numnames :=
  767.   numnames 'namesleft :=
  768.     { namesleft #0 > }
  769. #if NAME_FULL
  770.     { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
  771. #else
  772.     { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
  773. #endif NAME_FULL
  774.       nameptr #1 >
  775.         { namesleft #1 >
  776.             { ", " * t * }
  777.             { numnames #2 >
  778.                 { "," * }
  779.                 'skip$
  780.               if$
  781.               t "others" =
  782.                 { " et~al." * }
  783.                 { " and " * t * }
  784.               if$
  785.             }
  786.           if$
  787.         }
  788.         't
  789.       if$
  790.       nameptr #1 + 'nameptr :=
  791.       namesleft #1 - 'namesleft :=
  792.     }
  793.   while$
  794. }
  795.  
  796. FUNCTION {format.authors}
  797. { author empty$
  798.     { "" }
  799.     { author format.names }
  800.   if$
  801. }
  802.  
  803. FUNCTION {format.editors}
  804. { editor empty$
  805.     { "" }
  806.     { editor format.names
  807.       editor num.names$ #1 >
  808.         { ", editors" * }
  809.         { ", editor" * }
  810.       if$
  811.     }
  812.   if$
  813. }
  814.  
  815. FUNCTION {format.isbn}
  816. { isbn empty$
  817.     { "" }
  818.     { new.block "ISBN " isbn * }
  819.   if$
  820. }
  821.  
  822. FUNCTION {format.issn}
  823. { issn empty$
  824.     { "" }
  825.     { new.block "ISSN " issn * }
  826.   if$
  827. }
  828.  
  829. % The format.title function is used for non-book-like titles.
  830. % For most styles we convert to lowercase (except for the very first letter,
  831. % and except for the first one after a colon (followed by whitespace)),
  832. % and hope the user has brace-surrounded words that need to stay capitilized;
  833. % for some styles, however, we leave it as it is in the database.
  834.  
  835. FUNCTION {format.title}
  836. { title empty$
  837.     { "" }
  838. #if ATIT_LOWER
  839.     { title "t" change.case$ }
  840. #else
  841.     'title
  842. #endif ATIT_LOWER
  843.   if$
  844. }
  845.  
  846. % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
  847. % constant glob_str_size, the maximum length of a global string variable.
  848. % Analogously, BibTeX sets the global integer variable entry.max$ to
  849. % ent_str_size, the maximum length of an entry string variable.
  850. % The style designer may change these if necessary (but this is unlikely)
  851.  
  852. % The n.dashify function makes each single `-' in a string a double `--'
  853. % if it's not already
  854. %
  855. % pseudoVAR: pageresult: STRING         (it's what's accumulated on the stack)
  856. %
  857. % n.dashify(s) ==
  858. %  BEGIN
  859. %       t := s
  860. %       pageresult := ""
  861. %       while (not empty$(t))
  862. %         do
  863. %           if (first character of t = "-")
  864. %             then
  865. %               if (next character isn't)
  866. %                 then
  867. %                   pageresult := pageresult * "--"
  868. %                   t := t with the "-" removed
  869. %                 else
  870. %                   while (first character of t = "-")
  871. %                     do
  872. %                       pageresult := pageresult * "-"
  873. %                       t := t with the "-" removed
  874. %                     od
  875. %               fi
  876. %             else
  877. %               pageresult := pageresult * the first character
  878. %               t := t with the first character removed
  879. %           fi
  880. %         od
  881. %       return pageresult
  882. %  END
  883.  
  884. FUNCTION {n.dashify}
  885. { 't :=
  886.   ""
  887.     { t empty$ not }
  888.     { t #1 #1 substring$ "-" =
  889.         { t #1 #2 substring$ "--" = not
  890.             { "--" *
  891.               t #2 global.max$ substring$ 't :=
  892.             }
  893.             {   { t #1 #1 substring$ "-" = }
  894.                 { "-" *
  895.                   t #2 global.max$ substring$ 't :=
  896.                 }
  897.               while$
  898.             }
  899.           if$
  900.         }
  901.         { t #1 #1 substring$ *
  902.           t #2 global.max$ substring$ 't :=
  903.         }
  904.       if$
  905.     }
  906.   while$
  907. }
  908.  
  909. % The format.date function is for the month and year, but we give a warning if
  910. % there's an empty year but the month is there, and we return the empty string
  911. % if they're both empty.
  912.  
  913. FUNCTION {format.date}
  914. { year empty$
  915.     { month empty$
  916.         { "" }
  917.         { "there's a month but no year in " cite$ * warning$
  918.           month
  919.         }
  920.       if$
  921.     }
  922.     { month empty$
  923.         'year
  924.         { month " " * year * }
  925.       if$
  926.     }
  927.   if$
  928. }
  929.  
  930. % The format.btitle is for formatting the title field when it is a book-like
  931. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  932.  
  933. FUNCTION {format.btitle}
  934. { title emphasize
  935. }
  936.  
  937. % For several functions we'll need to connect two strings with a
  938. % tie (~) if the second one isn't very long (fewer than 3 characters).
  939. % The tie.or.space.connect function does that.  It concatenates the two
  940. % strings on top of the stack, along with either a tie or space between
  941. % them, and puts this concatenation back onto the stack:
  942. %
  943. % tie.or.space.connect(str1,str2) ==
  944. %    BEGIN
  945. %       if text.length$(str2) < 3
  946. %         then return the concatenation of str1, "~", and str2
  947. %         else return the concatenation of str1, " ", and str2
  948. %    END
  949.  
  950. FUNCTION {tie.or.space.connect}
  951. { duplicate$ text.length$ #3 <
  952.     { "~" }
  953.     { " " }
  954.   if$
  955.   swap$ * *
  956. }
  957.  
  958. % The either.or.check function complains if both fields or an either-or pair
  959. % are nonempty.
  960. %
  961. % either.or.check(t,s) ==
  962. %  BEGIN
  963. %       if empty$(s) then
  964. %           warning$(can't use both " * t * " fields in " * cite$)
  965. %       fi
  966. %  END
  967.  
  968. FUNCTION {either.or.check}
  969. { empty$
  970.     'pop$
  971.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  972.   if$
  973. }
  974.  
  975. % The format.bvolume function is for formatting the volume and perhaps
  976. % series name of a multivolume work.  If both a volume and a series field
  977. % are there, we assume the series field is the title of the whole multivolume
  978. % work (the title field should be the title of the thing being referred to),
  979. % and we add an "of <series>".  This function is called in mid-sentence.
  980.  
  981. FUNCTION {format.bvolume}
  982. { volume empty$
  983.     { "" }
  984.     { "volume" volume tie.or.space.connect
  985.       series empty$
  986.         'skip$
  987.         { " of " * series emphasize * }
  988.       if$
  989.       "volume and number" number either.or.check
  990.     }
  991.   if$
  992. }
  993.  
  994. % The format.number.series function is for formatting the series name
  995. % and perhaps number of a work in a series.  This function is similar to
  996. % format.bvolume, although for this one the series must exist (and the
  997. % volume must not exist).  If the number field is empty we output either
  998. % the series field unchanged if it exists or else the null string.
  999. % If both the number and series fields are there we assume the series field
  1000. % gives the name of the whole series (the title field should be the title
  1001. % of the work being one referred to), and we add an "in <series>".
  1002. % We capitilize Number when this function is used at the beginning of a block.
  1003.  
  1004. FUNCTION {format.number.series}
  1005. { volume empty$
  1006.     { number empty$
  1007.         { series field.or.null }
  1008.         { output.state mid.sentence =
  1009.             { "number" }
  1010.             { "Number" }
  1011.           if$
  1012.           number tie.or.space.connect
  1013.           series empty$
  1014.             { "there's a number but no series in " cite$ * warning$ }
  1015.             { " in " * series * }
  1016.           if$
  1017.         }
  1018.       if$
  1019.     }
  1020.     { "" }
  1021.   if$
  1022. }
  1023.  
  1024. % The format.edition function appends " edition" to the edition, if present.
  1025. % We lowercase the edition (it should be something like "Third"), because
  1026. % this doesn't start a sentence.
  1027.  
  1028. FUNCTION {format.edition}
  1029. { edition empty$
  1030.     { "" }
  1031.     { output.state mid.sentence =
  1032.         { edition "l" change.case$ " edition" * }
  1033.         { edition "t" change.case$ " edition" * }
  1034.       if$
  1035.     }
  1036.   if$
  1037. }
  1038.  
  1039. % The format.pages function is used for formatting a page range in a book
  1040. % (and in rare circumstances, an article).
  1041. %
  1042. % The multi.page.check function examines the page field for a "-" or "," or "+"
  1043. % so that format.pages can use "page" instead of "pages" if none exists.
  1044. % Note: global.max$ here means "take the rest of the string"
  1045. %
  1046. % VAR: multiresult: INTEGER     (actually, a boolean)
  1047. %
  1048. % multi.page.check(s) ==
  1049. %  BEGIN
  1050. %       t := s
  1051. %       multiresult := false
  1052. %       while ((not multiresult) and (not empty$(t)))
  1053. %         do
  1054. %           if (first character of t = "-" or "," or "+")
  1055. %             then multiresult := true
  1056. %             else t := t with the first character removed
  1057. %           fi
  1058. %         od
  1059. %       return multiresult
  1060. %  END
  1061.  
  1062. INTEGERS { multiresult }
  1063.  
  1064. FUNCTION {multi.page.check}
  1065. { 't :=
  1066.   #0 'multiresult :=
  1067.     { multiresult not
  1068.       t empty$ not
  1069.       and
  1070.     }
  1071.     { t #1 #1 substring$
  1072.       duplicate$ "-" =
  1073.       swap$ duplicate$ "," =
  1074.       swap$ "+" =
  1075.       or or
  1076.         { #1 'multiresult := }
  1077.         { t #2 global.max$ substring$ 't := }
  1078.       if$
  1079.     }
  1080.   while$
  1081.   multiresult
  1082. }
  1083.  
  1084. % This function doesn't begin a sentence so "pages" isn't capitalized.
  1085. % Other functions that use this should keep that in mind.
  1086.  
  1087. FUNCTION {format.pages}
  1088. { pages empty$
  1089.     { "" }
  1090.     { pages multi.page.check
  1091.         { "pages" pages n.dashify tie.or.space.connect }
  1092.         { "page" pages tie.or.space.connect }
  1093.       if$
  1094.     }
  1095.   if$
  1096. }
  1097.  
  1098. % The format.vol.num.pages function is for the volume, number, and page range
  1099. % of a journal article.  We use the format:  vol(number):pages, with some
  1100. % variations for empty fields.  This doesn't begin a sentence.
  1101.  
  1102. FUNCTION {format.vol.num.pages}
  1103. { volume field.or.null
  1104.   number empty$
  1105.     'skip$
  1106.     { "\penalty0 (" number * ")" * *
  1107.       volume empty$
  1108.         { "there's a number but no volume in " cite$ * warning$ }
  1109.         'skip$
  1110.       if$
  1111.     }
  1112.   if$
  1113.   pages empty$
  1114.     'skip$
  1115.     { duplicate$ empty$
  1116.         { pop$ format.pages }
  1117.         { ":\penalty0 " * pages n.dashify * }
  1118.       if$
  1119.     }
  1120.   if$
  1121. }
  1122.  
  1123.  
  1124. % The format.chapter.pages, if the chapter is present, puts whatever is in the
  1125. % type field (or else "chapter" if type is empty) in front of a chapter number.
  1126. % It then appends the pages, if present.  This doesn't begin a sentence.
  1127.  
  1128. FUNCTION {format.chapter.pages}
  1129. { chapter empty$
  1130.     'format.pages
  1131.     { type empty$
  1132.         { "chapter" }
  1133.         { type "l" change.case$ }
  1134.       if$
  1135.       chapter tie.or.space.connect
  1136.       pages empty$
  1137.         'skip$
  1138.         { ", " * format.pages * }
  1139.       if$
  1140.     }
  1141.   if$
  1142. }
  1143.  
  1144. % The format.in.ed.booktitle function is used for starting out a sentence
  1145. % that begins "In <booktitle>", putting an editor before the title if one
  1146. % exists.
  1147.  
  1148. FUNCTION {format.in.ed.booktitle}
  1149. { booktitle empty$
  1150.     { "" }
  1151.     { editor empty$
  1152.         { "In " booktitle emphasize * }
  1153.         { "In " format.editors * ", " * booktitle emphasize * }
  1154.       if$
  1155.     }
  1156.   if$
  1157. }
  1158.  
  1159. % The function empty.misc.check complains if all six fields are empty, and
  1160. % if there's been no sorting or alphabetic-label complaint.
  1161.  
  1162. FUNCTION {empty.misc.check}
  1163. { author empty$ title empty$ howpublished empty$
  1164.   month empty$ year empty$ note empty$
  1165.   and and and and and
  1166. #if SORTED
  1167.   key empty$ not and
  1168. #else !SORTED
  1169. #if LAB_ALPH
  1170.   key empty$ not and
  1171. #endif LAB_ALPH
  1172. #endif SORTED
  1173.     { "all relevant fields are empty in " cite$ * warning$ }
  1174.     'skip$
  1175.   if$
  1176. }
  1177.  
  1178. % The function format.thesis.type returns either the (case-changed) type field,
  1179. % if it is defined, or else the default string already on the stack
  1180. % (like "Master's thesis" or "PhD thesis").
  1181.  
  1182. FUNCTION {format.thesis.type}
  1183. { type empty$
  1184.     'skip$
  1185.     { pop$
  1186.       type "t" change.case$
  1187.     }
  1188.   if$
  1189. }
  1190.  
  1191. % The function format.tr.number makes a string starting with "Technical Report"
  1192. % (or type, if that field is defined), followed by the number if there is one;
  1193. % it returns the starting part (with a case change) even if there is no number.
  1194. % This is used at the beginning of a sentence.
  1195.  
  1196. FUNCTION {format.tr.number}
  1197. { type empty$
  1198.     { "Technical Report" }
  1199.     'type
  1200.   if$
  1201.   number empty$
  1202.     { "t" change.case$ }
  1203.     { number tie.or.space.connect }
  1204.   if$
  1205. }
  1206.  
  1207. % Now come the cross-referencing functions (these are invoked because
  1208. % one entry in the database file(s) cross-references another, by giving
  1209. % the other entry's database key in a `crossref' field).  This feature
  1210. % allows one or more titled things that are part of a larger titled
  1211. % thing to cross-reference the larger thing.  These styles allow for
  1212. % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
  1213. % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
  1214. % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
  1215. % Each of these is explained in more detail later.
  1216. %
  1217. % An ARTICLE entry type may cross reference another ARTICLE (this is
  1218. % intended for when an entire journal is devoted to a single topic---
  1219. % but since there is no JOURNAL entry type, the journal, too, should be
  1220. % classified as an ARTICLE but without the author and title fields).
  1221. % This will result in two warning messages for the journal's entry
  1222. % if it's included in the reference list, but such is life.
  1223. %
  1224. % format.article.crossref ==
  1225. %  BEGIN
  1226. %       if empty$(key) then
  1227. %           if empty$(journal) then
  1228. %               warning$("need key or journal for " * cite$ *
  1229. %                                               " to crossref " * crossref)
  1230. %               return(" \cite{" * crossref * "}")
  1231. %           else
  1232. %               return("In " * emphasize.correct (journal) *
  1233. %                                               " \cite{" * crossref * "}")
  1234. %               fi
  1235. %       else
  1236. %           return("In " * key * " \cite{" * crossref * "}")
  1237. %       fi
  1238. %  END
  1239. %
  1240. % The other cross-referencing functions are similar, so no "comment version"
  1241. % will be given for them.
  1242.  
  1243. FUNCTION {format.article.crossref}
  1244. { key empty$
  1245.     { journal empty$
  1246.         { "need key or journal for " cite$ * " to crossref " * crossref *
  1247.           warning$
  1248.           ""
  1249.         }
  1250.         { "In {\em " journal * "\/}" * }
  1251.       if$
  1252.     }
  1253.     { "In " key * }
  1254.   if$
  1255.   " \cite{" * crossref * "}" *
  1256. }
  1257.  
  1258. % We use just the last names of editors for a cross reference: either
  1259. % "editor", or "editor1 and editor2", or "editor1 et~al." depending on
  1260. % whether there are one, or two, or more than two editors.
  1261.  
  1262. FUNCTION {format.crossref.editor}
  1263. { editor #1 "{vv~}{ll}" format.name$
  1264.   editor num.names$ duplicate$
  1265.   #2 >
  1266.     { pop$ " et~al." * }
  1267.     { #2 <
  1268.         'skip$
  1269.         { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1270.             { " et~al." * }
  1271.             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
  1272.           if$
  1273.         }
  1274.       if$
  1275.     }
  1276.   if$
  1277. }
  1278.  
  1279. % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
  1280. % multivolume work) may cross reference another BOOK (the entire multivolume).
  1281. % Usually there will be an editor, in which case we use that to construct the
  1282. % cross reference; otherwise we use a nonempty key field or else the series
  1283. % field (since the series gives the title of the multivolume work).
  1284.  
  1285. FUNCTION {format.book.crossref}
  1286. { volume empty$
  1287.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1288.       "In "
  1289.     }
  1290.     { "Volume" volume tie.or.space.connect
  1291.       " of " *
  1292.     }
  1293.   if$
  1294.   editor empty$
  1295.   editor field.or.null author field.or.null =
  1296.   or
  1297.     { key empty$
  1298.         { series empty$
  1299.             { "need editor, key, or series for " cite$ * " to crossref " *
  1300.               crossref * warning$
  1301.               "" *
  1302.             }
  1303.             { "{\em " * series * "\/}" * }
  1304.           if$
  1305.         }
  1306.         { key * }
  1307.       if$
  1308.     }
  1309.     { format.crossref.editor * }
  1310.   if$
  1311.   " \cite{" * crossref * "}" *
  1312. }
  1313.  
  1314. % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
  1315. % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
  1316. % Often there will be an editor, in which case we use that to construct
  1317. % the cross reference; otherwise we use a nonempty key field or else
  1318. % the booktitle field (which gives the cross-referenced work's title).
  1319.  
  1320. FUNCTION {format.incoll.inproc.crossref}
  1321. { editor empty$
  1322.   editor field.or.null author field.or.null =
  1323.   or
  1324.     { key empty$
  1325.         { booktitle empty$
  1326.             { "need editor, key, or booktitle for " cite$ * " to crossref " *
  1327.               crossref * warning$
  1328.               ""
  1329.             }
  1330.             { "In {\em " booktitle * "\/}" * }
  1331.           if$
  1332.         }
  1333.         { "In " key * }
  1334.       if$
  1335.     }
  1336.     { "In " format.crossref.editor * }
  1337.   if$
  1338.   " \cite{" * crossref * "}" *
  1339. }
  1340.  
  1341. % Now we define the type functions for all entry types that may appear
  1342. % in the .BIB file---e.g., functions like `article' and `book'.  These
  1343. % are the routines that actually generate the .BBL-file output for
  1344. % the entry.  These must all precede the READ command.  In addition, the
  1345. % style designer should have a function `default.type' for unknown types.
  1346. % Note: The fields (within each list) are listed in order of appearance,
  1347. % except as described for an `inbook' or a `proceedings'.
  1348. %
  1349. % The article function is for an article in a journal.  An article may
  1350. % CROSSREF another article.
  1351. %       Required fields: author, title, journal, year
  1352. %       Optional fields: volume, number, pages, month, note
  1353. %
  1354. % article ==
  1355. %  BEGIN
  1356. %       output.bibitem
  1357. %       output.check(format.authors,"author")
  1358. %       new.block
  1359. %       output.check(format.title,"title")
  1360. %       new.block
  1361. %       if missing$(crossref) then
  1362. %           output.check(emphasize(journal),"journal")
  1363. %           output(format.vol.num.pages)
  1364. %           output.check(format.date,"year")
  1365. %       else
  1366. %           output.nonnull(format.article.crossref)
  1367. %           output(format.pages)
  1368. %       fi
  1369. %       new.block
  1370. %       output(note)
  1371. %       fin.entry
  1372. %  END
  1373. %
  1374. % The book function is for a whole book.  A book may CROSSREF another book.
  1375. %       Required fields: author or editor, title, publisher, year
  1376. %       Optional fields: volume or number, series, address, edition, month,
  1377. %                       note
  1378. %
  1379. % book ==
  1380. %  BEGIN
  1381. %       if empty$(author) then output.check(format.editors,"author and editor")
  1382. %       else    output.check(format.authors,"author")
  1383. %               if missing$(crossref) then
  1384. %                   either.or.check("author and editor",editor)
  1385. %               fi
  1386. %       fi
  1387. %       new.block
  1388. %       output.check(format.btitle,"title")
  1389. %       if missing$(crossref) then
  1390. %           output(format.bvolume)
  1391. %           new.block
  1392. %           output(format.number.series)
  1393. %           new.sentence
  1394. %           output.check(publisher,"publisher")
  1395. %           output(address)
  1396. %       else
  1397. %           new.block
  1398. %           output.nonnull(format.book.crossref)
  1399. %       fi
  1400. %       output(format.edition)
  1401. %       output.check(format.date,"year")
  1402. %       new.block
  1403. %       output(note)
  1404. %       fin.entry
  1405. %  END
  1406. %
  1407. % The other entry functions are all quite similar, so no "comment version"
  1408. % will be given for them.
  1409.  
  1410. FUNCTION {article}
  1411. { output.bibitem
  1412.   format.authors "author" output.check
  1413.   new.block
  1414.   format.title "title" output.check
  1415.   new.block
  1416.   crossref missing$
  1417.     { journal emphasize "journal" output.check
  1418.       format.vol.num.pages output
  1419.       format.date "year" output.check
  1420.     }
  1421.     { format.article.crossref output.nonnull
  1422.       format.pages output
  1423.     }
  1424.   if$
  1425.   new.block
  1426.   note output
  1427.   fin.entry
  1428. }
  1429.  
  1430. FUNCTION {book}
  1431. { output.bibitem
  1432.   author empty$
  1433.     { format.editors "author and editor" output.check }
  1434.     { format.authors output.nonnull
  1435.       crossref missing$
  1436.         { "author and editor" editor either.or.check }
  1437.         'skip$
  1438.       if$
  1439.     }
  1440.   if$
  1441.   new.block
  1442.   format.btitle "title" output.check
  1443.   crossref missing$
  1444.     { format.bvolume output
  1445.       new.block
  1446.       format.number.series output
  1447.       new.sentence
  1448.       publisher "publisher" output.check
  1449.       address output
  1450.     }
  1451.     { new.block
  1452.       format.book.crossref output.nonnull
  1453.     }
  1454.   if$
  1455.   format.edition output
  1456.   format.date "year" output.check
  1457.   format.isbn output
  1458.   new.block
  1459.   note output
  1460.   fin.entry
  1461. }
  1462.  
  1463. % A booklet is a bound thing without a publisher or sponsoring institution.
  1464. %       Required: title
  1465. %       Optional: author, howpublished, address, month, year, note
  1466.  
  1467. FUNCTION {booklet}
  1468. { output.bibitem
  1469.   format.authors output
  1470.   new.block
  1471.   format.title "title" output.check
  1472.   howpublished address new.block.checkb
  1473.   howpublished output
  1474.   address output
  1475.   format.date output
  1476.   format.isbn output
  1477.   new.block
  1478.   note output
  1479.   fin.entry
  1480. }
  1481.  
  1482. % For the conference entry type, see inproceedings.
  1483.  
  1484. % An inbook is a piece of a book: either a chapter and/or a page range.
  1485. % It may CROSSREF a book.  If there's no volume field, the type field
  1486. % will come before number and series.
  1487. %       Required: author or editor, title, chapter and/or pages, publisher,year
  1488. %       Optional: volume or number, series, type, address, edition, month, note
  1489.  
  1490. FUNCTION {inbook}
  1491. { output.bibitem
  1492.   author empty$
  1493.     { format.editors "author and editor" output.check }
  1494.     { format.authors output.nonnull
  1495.       crossref missing$
  1496.         { "author and editor" editor either.or.check }
  1497.         'skip$
  1498.       if$
  1499.     }
  1500.   if$
  1501.   new.block
  1502.   format.btitle "title" output.check
  1503.   crossref missing$
  1504.     { format.bvolume output
  1505.       format.chapter.pages "chapter and pages" output.check
  1506.       new.block
  1507.       format.number.series output
  1508.       new.sentence
  1509.       publisher "publisher" output.check
  1510.       address output
  1511.     }
  1512.     { format.chapter.pages "chapter and pages" output.check
  1513.       new.block
  1514.       format.book.crossref output.nonnull
  1515.     }
  1516.   if$
  1517.   format.edition output
  1518.   format.date "year" output.check
  1519.   format.isbn output
  1520.   new.block
  1521.   note output
  1522.   fin.entry
  1523. }
  1524.  
  1525. % An incollection is like inbook, but where there is a separate title
  1526. % for the referenced thing (and perhaps an editor for the whole).
  1527. % An incollection may CROSSREF a book.
  1528. %       Required: author, title, booktitle, publisher, year
  1529. %       Optional: editor, volume or number, series, type, chapter, pages,
  1530. %                       address, edition, month, note
  1531.  
  1532. FUNCTION {incollection}
  1533. { output.bibitem
  1534.   format.authors "author" output.check
  1535.   new.block
  1536.   format.title "title" output.check
  1537.   new.block
  1538.   crossref missing$
  1539.     { format.in.ed.booktitle "booktitle" output.check
  1540.       format.bvolume output
  1541.       format.number.series output
  1542.       format.chapter.pages output
  1543.       new.sentence
  1544.       publisher "publisher" output.check
  1545.       address output
  1546.       format.edition output
  1547.       format.date "year" output.check
  1548.     }
  1549.     { format.incoll.inproc.crossref output.nonnull
  1550.       format.chapter.pages output
  1551.     }
  1552.   if$
  1553.   format.isbn output
  1554.   new.block
  1555.   note output
  1556.   fin.entry
  1557. }
  1558.  
  1559. % An inproceedings is an article in a conference proceedings, and it may
  1560. % CROSSREF a proceedings.  If there's no address field, the month (& year)
  1561. % will appear just before note.
  1562. %       Required: author, title, booktitle, year
  1563. %       Optional: editor, volume or number, series, pages, address, month,
  1564. %                       organization, publisher, note
  1565.  
  1566. FUNCTION {inproceedings}
  1567. { output.bibitem
  1568.   format.authors "author" output.check
  1569.   new.block
  1570.   format.title "title" output.check
  1571.   new.block
  1572.   crossref missing$
  1573.     { format.in.ed.booktitle "booktitle" output.check
  1574.       format.bvolume output
  1575.       format.number.series output
  1576.       format.pages output
  1577.       address empty$
  1578.         { organization publisher new.sentence.checkb
  1579.           organization output
  1580.           publisher output
  1581.           format.date "year" output.check
  1582.         }
  1583.         { address output.nonnull
  1584.           format.date "year" output.check
  1585.           new.sentence
  1586.           organization output
  1587.           publisher output
  1588.         }
  1589.       if$
  1590.     }
  1591.     { format.incoll.inproc.crossref output.nonnull
  1592.       format.pages output
  1593.     }
  1594.   if$
  1595.   format.isbn output
  1596.   new.block
  1597.   note output
  1598.   fin.entry
  1599. }
  1600.  
  1601. % The conference function is included for Scribe compatibility.
  1602.  
  1603. FUNCTION {conference} { inproceedings }
  1604.  
  1605. % A manual is technical documentation.
  1606. %       Required: title
  1607. %       Optional: author, organization, address, edition, month, year, note
  1608.  
  1609. FUNCTION {manual}
  1610. { output.bibitem
  1611.   author empty$
  1612.     { organization empty$
  1613.         'skip$
  1614.         { organization output.nonnull
  1615.           address output
  1616.         }
  1617.       if$
  1618.     }
  1619.     { format.authors output.nonnull }
  1620.   if$
  1621.   new.block
  1622.   format.btitle "title" output.check
  1623.   author empty$
  1624.     { organization empty$
  1625.         { address new.block.checka
  1626.           address output
  1627.         }
  1628.         'skip$
  1629.       if$
  1630.     }
  1631.     { organization address new.block.checkb
  1632.       organization output
  1633.       address output
  1634.     }
  1635.   if$
  1636.   format.edition output
  1637.   format.date output
  1638.   new.block
  1639.   note output
  1640.   fin.entry
  1641. }
  1642.  
  1643. % A mastersthesis is a Master's thesis.
  1644. %       Required: author, title, school, year
  1645. %       Optional: type, address, month, note
  1646.  
  1647. FUNCTION {mastersthesis}
  1648. { output.bibitem
  1649.   format.authors "author" output.check
  1650.   new.block
  1651.   format.title "title" output.check
  1652.   new.block
  1653.   "Master's thesis" format.thesis.type output.nonnull
  1654.   school "school" output.check
  1655.   address output
  1656.   format.date "year" output.check
  1657.   new.block
  1658.   note output
  1659.   fin.entry
  1660. }
  1661.  
  1662. % A misc is something that doesn't fit elsewhere.
  1663. %       Required: at least one of the `optional' fields
  1664. %       Optional: author, title, howpublished, month, year, note
  1665.  
  1666. FUNCTION {misc}
  1667. { output.bibitem
  1668.   format.authors output
  1669.   title howpublished new.block.checkb
  1670.   format.title output
  1671.   howpublished new.block.checka
  1672.   howpublished output
  1673.   format.date output
  1674.   format.issn output
  1675.   new.block
  1676.   note output
  1677.   fin.entry
  1678.   empty.misc.check
  1679. }
  1680.  
  1681. % A phdthesis is like a mastersthesis.
  1682. %       Required: author, title, school, year
  1683. %       Optional: type, address, month, note
  1684.  
  1685. FUNCTION {phdthesis}
  1686. { output.bibitem
  1687.   format.authors "author" output.check
  1688.   new.block
  1689.   format.btitle "title" output.check
  1690.   new.block
  1691.   "PhD thesis" format.thesis.type output.nonnull
  1692.   school "school" output.check
  1693.   address output
  1694.   format.date "year" output.check
  1695.   new.block
  1696.   note output
  1697.   fin.entry
  1698. }
  1699.  
  1700. % A periodical is a publication that appears at regular
  1701. % intervals.  This includes journals, magazines, and newspapers.
  1702. % If there is an organization but no editor field, the
  1703. % organization will appear as the first optional field (we try to
  1704. % make the first block nonempty); if there's no address field,
  1705. % the month (& year) will appear just before note.
  1706. %       Required: title, key
  1707. %       Optional: editor, volume, number, series, address, month, year,
  1708. %                       organization, publisher, note, issn,
  1709. %                       howpublished
  1710.  
  1711. FUNCTION {periodical}
  1712. { output.bibitem
  1713.   editor empty$
  1714.     { organization output }
  1715.     { format.editors output.nonnull }
  1716.   if$
  1717.   new.block
  1718.   title emphasize "title" output.check
  1719. %  format.bvolume output
  1720. %  format.number.series output
  1721.   format.vol.num.pages output
  1722.   format.date output
  1723.   format.issn output
  1724.   new.sentence
  1725.   publisher output
  1726.   address output
  1727.   howpublished new.block.checka
  1728.   howpublished output
  1729.   new.block
  1730.   note output
  1731.   fin.entry
  1732. }
  1733.  
  1734. % A proceedings is a conference proceedings.
  1735. % If there is an organization but no editor field, the organization will
  1736. % appear as the first optional field (we try to make the first block nonempty);
  1737. % if there's no address field, the month (& year) will appear just before note.
  1738. %       Required: title, year
  1739. %       Optional: editor, volume or number, series, address, month,
  1740. %                       organization, publisher, note
  1741.  
  1742. FUNCTION {proceedings}
  1743. { output.bibitem
  1744.   editor empty$
  1745.     { organization output }
  1746.     { format.editors output.nonnull }
  1747.   if$
  1748.   new.block
  1749.   format.btitle "title" output.check
  1750.   format.bvolume output
  1751.   format.number.series output
  1752.   address empty$
  1753.     { editor empty$
  1754.         { publisher new.sentence.checka }
  1755.         { organization publisher new.sentence.checkb
  1756.           organization output
  1757.         }
  1758.       if$
  1759.       publisher output
  1760.       format.date "year" output.check
  1761.     }
  1762.     { address output.nonnull
  1763.       format.date "year" output.check
  1764.       new.sentence
  1765.       editor empty$
  1766.         'skip$
  1767.         { organization output }
  1768.       if$
  1769.       publisher output
  1770.     }
  1771.   if$
  1772.   format.isbn output
  1773.   new.block
  1774.   note output
  1775.   fin.entry
  1776. }
  1777.  
  1778. % A techreport is a technical report.
  1779. %       Required: author, title, institution, year
  1780. %       Optional: type, number, address, month, note
  1781.  
  1782. FUNCTION {techreport}
  1783. { output.bibitem
  1784.   format.authors "author" output.check
  1785.   new.block
  1786.   format.title "title" output.check
  1787.   new.block
  1788.   format.tr.number output.nonnull
  1789.   institution "institution" output.check
  1790.   address output
  1791.   format.date "year" output.check
  1792.   new.block
  1793.   note output
  1794.   fin.entry
  1795. }
  1796.  
  1797. % An unpublished is something that hasn't been published.
  1798. %       Required: author, title, note
  1799. %       Optional: month, year
  1800.  
  1801. FUNCTION {unpublished}
  1802. { output.bibitem
  1803.   format.authors "author" output.check
  1804.   new.block
  1805.   format.title "title" output.check
  1806.   new.block
  1807.   note "note" output.check
  1808.   format.date output
  1809.   fin.entry
  1810. }
  1811.  
  1812. % We use entry type `misc' for an unknown type; BibTeX gives a warning.
  1813.  
  1814. FUNCTION {default.type} { misc }
  1815.  
  1816. % Here are macros for common things that may vary from style to style.
  1817. % Users are encouraged to use these macros.
  1818. %
  1819. % Months are either written out in full or abbreviated
  1820.  
  1821. #if MONTH_FULL
  1822.  
  1823. MACRO {jan} {"January"}
  1824.  
  1825. MACRO {feb} {"February"}
  1826.  
  1827. MACRO {mar} {"March"}
  1828.  
  1829. MACRO {apr} {"April"}
  1830.  
  1831. MACRO {may} {"May"}
  1832.  
  1833. MACRO {jun} {"June"}
  1834.  
  1835. MACRO {jul} {"July"}
  1836.  
  1837. MACRO {aug} {"August"}
  1838.  
  1839. MACRO {sep} {"September"}
  1840.  
  1841. MACRO {oct} {"October"}
  1842.  
  1843. MACRO {nov} {"November"}
  1844.  
  1845. MACRO {dec} {"December"}
  1846.  
  1847. #else !MONTH_FULL
  1848.  
  1849. MACRO {jan} {"Jan."}
  1850.  
  1851. MACRO {feb} {"Feb."}
  1852.  
  1853. MACRO {mar} {"Mar."}
  1854.  
  1855. MACRO {apr} {"Apr."}
  1856.  
  1857. MACRO {may} {"May"}
  1858.  
  1859. MACRO {jun} {"June"}
  1860.  
  1861. MACRO {jul} {"July"}
  1862.  
  1863. MACRO {aug} {"Aug."}
  1864.  
  1865. MACRO {sep} {"Sept."}
  1866.  
  1867. MACRO {oct} {"Oct."}
  1868.  
  1869. MACRO {nov} {"Nov."}
  1870.  
  1871. MACRO {dec} {"Dec."}
  1872.  
  1873. #endif MONTH_FULL
  1874.  
  1875. % Journals are either written out in full or abbreviated;
  1876. % the abbreviations are like those found in ACM publications.
  1877. %
  1878. % To get a completely different set of abbreviations, it may be best to make
  1879. % a separate .bib file with nothing but those abbreviations; users could then
  1880. % include that file name as the first argument to the \bibliography command
  1881.  
  1882. #if JOUR_FULL
  1883.  
  1884. MACRO {acmcs} {"ACM Computing Surveys"}
  1885.  
  1886. MACRO {acta} {"Acta Informatica"}
  1887.  
  1888. MACRO {cacm} {"Communications of the ACM"}
  1889.  
  1890. MACRO {ibmjrd} {"IBM Journal of Research and Development"}
  1891.  
  1892. MACRO {ibmsj} {"IBM Systems Journal"}
  1893.  
  1894. MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
  1895.  
  1896. MACRO {ieeetc} {"IEEE Transactions on Computers"}
  1897.  
  1898. MACRO {ieeetcad}
  1899.  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
  1900.  
  1901. MACRO {ipl} {"Information Processing Letters"}
  1902.  
  1903. MACRO {jacm} {"Journal of the ACM"}
  1904.  
  1905. MACRO {jcss} {"Journal of Computer and System Sciences"}
  1906.  
  1907. MACRO {scp} {"Science of Computer Programming"}
  1908.  
  1909. MACRO {sicomp} {"SIAM Journal on Computing"}
  1910.  
  1911. MACRO {tocs} {"ACM Transactions on Computer Systems"}
  1912.  
  1913. MACRO {tods} {"ACM Transactions on Database Systems"}
  1914.  
  1915. MACRO {tog} {"ACM Transactions on Graphics"}
  1916.  
  1917. MACRO {toms} {"ACM Transactions on Mathematical Software"}
  1918.  
  1919. MACRO {toois} {"ACM Transactions on Office Information Systems"}
  1920.  
  1921. MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
  1922.  
  1923. MACRO {tcs} {"Theoretical Computer Science"}
  1924.  
  1925. #else !JOUR_FULL
  1926.  
  1927. MACRO {acmcs} {"ACM Comput. Surv."}
  1928.  
  1929. MACRO {acta} {"Acta Inf."}
  1930.  
  1931. MACRO {cacm} {"Commun. ACM"}
  1932.  
  1933. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  1934.  
  1935. MACRO {ibmsj} {"IBM Syst.~J."}
  1936.  
  1937. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  1938.  
  1939. MACRO {ieeetc} {"IEEE Trans. Comput."}
  1940.  
  1941. MACRO {ieeetcad}
  1942.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  1943.  
  1944. MACRO {ipl} {"Inf. Process. Lett."}
  1945.  
  1946. MACRO {jacm} {"J.~ACM"}
  1947.  
  1948. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  1949.  
  1950. MACRO {scp} {"Sci. Comput. Programming"}
  1951.  
  1952. MACRO {sicomp} {"SIAM J. Comput."}
  1953.  
  1954. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  1955.  
  1956. MACRO {tods} {"ACM Trans. Database Syst."}
  1957.  
  1958. MACRO {tog} {"ACM Trans. Gr."}
  1959.  
  1960. MACRO {toms} {"ACM Trans. Math. Softw."}
  1961.  
  1962. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  1963.  
  1964. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  1965.  
  1966. MACRO {tcs} {"Theoretical Comput. Sci."}
  1967.  
  1968. #endif JOUR_FULL
  1969.  
  1970. % Now we read in the .BIB entries.
  1971.  
  1972. READ
  1973.  
  1974. % The sortify function converts to lower case after purify$ing; it's
  1975. % used in sorting and in computing alphabetic labels after sorting
  1976. %
  1977. % The chop.word(w,len,s) function returns either s or, if the first len
  1978. % letters of s equals w (this comparison is done in the third line of the
  1979. % function's definition), it returns that part of s after w.
  1980.  
  1981. #if SORTED
  1982.  
  1983. FUNCTION {sortify}
  1984. { purify$
  1985.   "l" change.case$
  1986. }
  1987.  
  1988. INTEGERS { len }
  1989.  
  1990. FUNCTION {chop.word}
  1991. { 's :=
  1992.   'len :=
  1993.   s #1 len substring$ =
  1994.     { s len #1 + global.max$ substring$ }
  1995.     's
  1996.   if$
  1997. }
  1998.  
  1999. #else !SORTED
  2000. #if LAB_ALPH
  2001.  
  2002. % We need the chop.word stuff for the dubious unsorted-list-with-labels case.
  2003.  
  2004. INTEGERS { len }
  2005.  
  2006. FUNCTION {chop.word}
  2007. { 's :=
  2008.   'len :=
  2009.   s #1 len substring$ =
  2010.     { s len #1 + global.max$ substring$ }
  2011.     's
  2012.   if$
  2013. }
  2014.  
  2015. #endif LAB_ALPH
  2016. #endif SORTED
  2017.  
  2018. % This long comment applies only to alphabetic labels
  2019. %
  2020. % The format.lab.names function makes a short label by using the initials of
  2021. % the von and Last parts of the names (but if there are more than four names,
  2022. % (i.e., people) it truncates after three and adds a superscripted "+";
  2023. % it also adds such a "+" if the last of multiple authors is "others").
  2024. % If there is only one name, and its von and Last parts combined have just
  2025. % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
  2026. % we take the first three letters of the last name.  The boolean
  2027. % et.al.char.used tells whether we've used a superscripted "+", so that we
  2028. % know whether to include a LaTeX macro for it.
  2029. %
  2030. % format.lab.names(s) ==
  2031. %  BEGIN
  2032. %       numnames := num.names$(s)
  2033. %       if numnames > 1 then
  2034. %           if numnames > 4 then
  2035. %               namesleft := 3
  2036. %           else
  2037. %               namesleft := numnames
  2038. %           nameptr := 1
  2039. %           nameresult := ""
  2040. %           while namesleft > 0
  2041. %             do
  2042. %               if (name_ptr = numnames) and
  2043. %                    format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  2044. %                  then nameresult := nameresult * "{\etalchar{+}}"
  2045. %                       et.al.char.used := true
  2046. %                  else nameresult := nameresult *
  2047. %                               format.name$(s, nameptr, "{v{}}{l{}}")
  2048. %               nameptr := nameptr + 1
  2049. %               namesleft := namesleft - 1
  2050. %             od
  2051. %           if numnames > 4 then
  2052. %               nameresult := nameresult * "{\etalchar{+}}"
  2053. %               et.al.char.used := true
  2054. %       else
  2055. %           t := format.name$(s, 1, "{v{}}{l{}}")
  2056. %           if text.length$(t) < 2 then % there's just one name-token
  2057. %               nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  2058. %           else
  2059. %               nameresult := t
  2060. %           fi
  2061. %       fi
  2062. %       return nameresult
  2063. %  END
  2064. %
  2065. % Exactly what fields we look at in constructing the primary part of the label
  2066. % depends on the entry type; this selectivity (as opposed to, say, always
  2067. % looking at author, then editor, then key) helps ensure that "ignored" fields,
  2068. % as described in the LaTeX book, really are ignored.  Note that MISC is part
  2069. % of the deepest `else' clause in the nested part of calc.label; thus, any
  2070. % unrecognized entry type in the database is handled correctly.
  2071. %
  2072. % There is one auxiliary function for each of the four different sequences of
  2073. % fields we use.  The first of these functions looks at the author field, and
  2074. % then, if necessary, the key field.  The other three functions, which might
  2075. % look at two fields and the key field, are similar, except that the key field
  2076. % takes precedence over the organization field (for labels---not for sorting).
  2077. %
  2078. % The calc.label function calculates the preliminary label of an entry, which
  2079. % is formed by taking three letters of information from the author or editor or
  2080. % key or organization field (depending on the entry type and on what's empty,
  2081. % but ignoring a leading "The " in the organization), and appending the last
  2082. % two characters (digits) of the year. It is an error if the appropriate fields
  2083. % among author, editor, organization, and key are missing, and we use
  2084. % the first three letters of the cite$ in desperation when this happens.
  2085. % The resulting label has the year part, but not the name part, purify$ed
  2086. % (purify$ing the year allows some sorting shenanigans by the user).
  2087. %
  2088. % This function also calculates the version of the label to be used in sorting.
  2089. %
  2090. % The final label may need a trailing 'a', 'b', etc., to distinguish it from
  2091. % otherwise identical labels, but we can't calculated those "extra.label"s
  2092. % until after sorting.
  2093. %
  2094. % calc.label ==
  2095. %  BEGIN
  2096. %       if type$ = "book" or "inbook" then
  2097. %           author.editor.key.label
  2098. %       else if type$ = "proceedings" then
  2099. %           editor.key.organization.label
  2100. %       else if type$ = "manual" then
  2101. %           author.key.organization.label
  2102. %       else
  2103. %           author.key.label
  2104. %       fi fi fi
  2105. %       label := label * substring$(purify$(field.or.null(year)), -1, 2)
  2106. %               % assuming we will also sort, we calculate a sort.label
  2107. %       sort.label := sortify(label), but use the last four, not two, digits
  2108. %  END
  2109.  
  2110. #if LAB_ALPH
  2111.  
  2112. INTEGERS { et.al.char.used }
  2113.  
  2114. FUNCTION {initialize.et.al.char.used}
  2115. { #0 'et.al.char.used :=
  2116. }
  2117.  
  2118. EXECUTE {initialize.et.al.char.used}
  2119.  
  2120. FUNCTION {format.lab.names}
  2121. { 's :=
  2122.   s num.names$ 'numnames :=
  2123.   numnames #1 >
  2124.     { numnames #4 >
  2125.         { #3 'namesleft := }
  2126.         { numnames 'namesleft := }
  2127.       if$
  2128.       #1 'nameptr :=
  2129.       ""
  2130.         { namesleft #0 > }
  2131.         { nameptr numnames =
  2132.             { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2133.                 { "{\etalchar{+}}" *
  2134.                   #1 'et.al.char.used :=
  2135.                 }
  2136.                 { s nameptr "{v{}}{l{}}" format.name$ * }
  2137.               if$
  2138.             }
  2139.             { s nameptr "{v{}}{l{}}" format.name$ * }
  2140.           if$
  2141.           nameptr #1 + 'nameptr :=
  2142.           namesleft #1 - 'namesleft :=
  2143.         }
  2144.       while$
  2145.       numnames #4 >
  2146.         { "{\etalchar{+}}" *
  2147.           #1 'et.al.char.used :=
  2148.         }
  2149.         'skip$
  2150.       if$
  2151.     }
  2152.     { s #1 "{v{}}{l{}}" format.name$
  2153.       duplicate$ text.length$ #2 <
  2154.         { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
  2155.         'skip$
  2156.       if$
  2157.     }
  2158.   if$
  2159. }
  2160.  
  2161. FUNCTION {author.key.label}
  2162. { author empty$
  2163.     { key empty$
  2164. #if SORTED
  2165.         { cite$ #1 #3 substring$ }
  2166. #else !SORTED           % need warning here because we won't give it later
  2167.         { "for label, need author or key in " cite$ * warning$
  2168.           cite$ #1 #3 substring$
  2169.         }
  2170. #endif SORTED
  2171.         { key #3 text.prefix$ }
  2172.       if$
  2173.     }
  2174.     { author format.lab.names }
  2175.   if$
  2176. }
  2177.  
  2178. FUNCTION {author.editor.key.label}
  2179. { author empty$
  2180.     { editor empty$
  2181.         { key empty$
  2182. #if SORTED
  2183.             { cite$ #1 #3 substring$ }
  2184. #else !SORTED           % need warning here because we won't give it later
  2185.             { "for label, need author, editor, or key in " cite$ * warning$
  2186.               cite$ #1 #3 substring$
  2187.             }
  2188. #endif SORTED
  2189.             { key #3 text.prefix$ }
  2190.           if$
  2191.         }
  2192.         { editor format.lab.names }
  2193.       if$
  2194.     }
  2195.     { author format.lab.names }
  2196.   if$
  2197. }
  2198.  
  2199. FUNCTION {author.key.organization.label}
  2200. { author empty$
  2201.     { key empty$
  2202.         { organization empty$
  2203. #if SORTED
  2204.             { cite$ #1 #3 substring$ }
  2205. #else !SORTED           % need warning here because we won't give it later
  2206.             { "for label, need author, key, or organization in " cite$ *
  2207.                                                                 warning$
  2208.               cite$ #1 #3 substring$
  2209.             }
  2210. #endif SORTED
  2211.             { "The " #4 organization chop.word #3 text.prefix$ }
  2212.           if$
  2213.         }
  2214.         { key #3 text.prefix$ }
  2215.       if$
  2216.     }
  2217.     { author format.lab.names }
  2218.   if$
  2219. }
  2220.  
  2221. FUNCTION {editor.key.organization.label}
  2222. { editor empty$
  2223.     { key empty$
  2224.         { organization empty$
  2225. #if SORTED
  2226.             { cite$ #1 #3 substring$ }
  2227. #else !SORTED           % need warning here because we won't give it later
  2228.             { "for label, need editor, key, or organization in " cite$ *
  2229.                                                                 warning$
  2230.               cite$ #1 #3 substring$
  2231.             }
  2232. #endif SORTED
  2233.             { "The " #4 organization chop.word #3 text.prefix$ }
  2234.           if$
  2235.         }
  2236.         { key #3 text.prefix$ }
  2237.       if$
  2238.     }
  2239.     { editor format.lab.names }
  2240.   if$
  2241. }
  2242.  
  2243. FUNCTION {calc.label}
  2244. { type$ "book" =
  2245.   type$ "inbook" =
  2246.   or
  2247.     'author.editor.key.label
  2248.     { type$ "proceedings" =
  2249.         'editor.key.organization.label
  2250.         { type$ "manual" =
  2251.             'author.key.organization.label
  2252.             'author.key.label
  2253.           if$
  2254.         }
  2255.       if$
  2256.     }
  2257.   if$
  2258.   duplicate$
  2259.   year field.or.null purify$ #-1 #2 substring$
  2260.   *
  2261.   'label :=
  2262.   year field.or.null purify$ #-1 #4 substring$
  2263.   *
  2264.   sortify 'sort.label :=
  2265. }
  2266.  
  2267. % It doesn't seem like a particularly good idea to use an order-of-citation
  2268. % reference list when using alphabetic labels, but we need to have a
  2269. % special pass to calculate labels when this happens.
  2270.  
  2271. #if !SORTED
  2272.  
  2273. ITERATE {calc.label}
  2274.  
  2275. #endif !SORTED
  2276.  
  2277. #endif LAB_ALPH
  2278.  
  2279. % When sorting, we compute the sortkey by executing "presort" on each entry.
  2280. % The presort key contains a number of "sortify"ed strings, concatenated
  2281. % with multiple blanks between them.  This makes things like "brinch  per"
  2282. % come before "brinch hansen  per".
  2283. %
  2284. % The fields used here are: the sort.label for alphabetic labels (as set by
  2285. % calc.label), followed by the author names (or editor names or organization
  2286. % (with a leading "The " removed) or key field, depending on entry type and on
  2287. % what's empty), followed by year, followed by the first bit of the title
  2288. % (chopping off a leading "The ", "A ", or "An ").
  2289. % Names are formatted: Von Last First Junior.
  2290. % The names within a part will be separated by a single blank
  2291. % (such as "brinch hansen"), two will separate the name parts themselves
  2292. % (except the von and last), three will separate the names,
  2293. % four will separate the names from year (and from label, if alphabetic),
  2294. % and four will separate year from title.
  2295. %
  2296. % The sort.format.names function takes an argument that should be in
  2297. % BibTeX name format, and returns a string containing "   "-separated
  2298. % names in the format described above.  The function is almost the same
  2299. % as format.names.
  2300.  
  2301. #if SORTED
  2302.  
  2303. FUNCTION {sort.format.names}
  2304. { 's :=
  2305.   #1 'nameptr :=
  2306.   ""
  2307.   s num.names$ 'numnames :=
  2308.   numnames 'namesleft :=
  2309.     { namesleft #0 > }
  2310.     { nameptr #1 >
  2311.         { "   " * }
  2312.         'skip$
  2313.       if$
  2314. #if NAME_FULL
  2315.       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
  2316. #else
  2317.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't :=
  2318. #endif NAME_FULL
  2319.       nameptr numnames = t "others" = and
  2320.         { "et al" * }
  2321.         { t sortify * }
  2322.       if$
  2323.       nameptr #1 + 'nameptr :=
  2324.       namesleft #1 - 'namesleft :=
  2325.     }
  2326.   while$
  2327. }
  2328.  
  2329. % The sort.format.title function returns the argument,
  2330. % but first any leading "A "'s, "An "'s, or "The "'s are removed.
  2331. % The chop.word function uses s, so we need another string variable, t
  2332.  
  2333. FUNCTION {sort.format.title}
  2334. { 't :=
  2335.   "A " #2
  2336.     "An " #3
  2337.       "The " #4 t chop.word
  2338.     chop.word
  2339.   chop.word
  2340.   sortify
  2341.   #1 global.max$ substring$
  2342. }
  2343.  
  2344. % The auxiliary functions here, for the presort function, are analogous to
  2345. % the ones for calc.label; the same comments apply, except that the
  2346. % organization field takes precedence here over the key field.  For sorting
  2347. % purposes, we still remove a leading "The " from the organization field.
  2348.  
  2349. FUNCTION {author.sort}
  2350. { author empty$
  2351.     { key empty$
  2352.         { "to sort, need author or key in " cite$ * warning$
  2353.           ""
  2354.         }
  2355.         { key sortify }
  2356.       if$
  2357.     }
  2358.     { author sort.format.names }
  2359.   if$
  2360. }
  2361.  
  2362. FUNCTION {author.editor.sort}
  2363. { author empty$
  2364.     { editor empty$
  2365.         { key empty$
  2366.             { "to sort, need author, editor, or key in " cite$ * warning$
  2367.               ""
  2368.             }
  2369.             { key sortify }
  2370.           if$
  2371.         }
  2372.         { editor sort.format.names }
  2373.       if$
  2374.     }
  2375.     { author sort.format.names }
  2376.   if$
  2377. }
  2378.  
  2379. FUNCTION {author.organization.sort}
  2380. { author empty$
  2381.     { organization empty$
  2382.         { key empty$
  2383.             { "to sort, need author, organization, or key in " cite$ * warning$
  2384.               ""
  2385.             }
  2386.             { key sortify }
  2387.           if$
  2388.         }
  2389.         { "The " #4 organization chop.word sortify }
  2390.       if$
  2391.     }
  2392.     { author sort.format.names }
  2393.   if$
  2394. }
  2395.  
  2396. FUNCTION {editor.organization.sort}
  2397. { editor empty$
  2398.     { organization empty$
  2399.         { key empty$
  2400.             { "to sort, need editor, organization, or key in " cite$ * warning$
  2401.               ""
  2402.             }
  2403.             { key sortify }
  2404.           if$
  2405.         }
  2406.         { "The " #4 organization chop.word sortify }
  2407.       if$
  2408.     }
  2409.     { editor sort.format.names }
  2410.   if$
  2411. }
  2412.  
  2413. % There is a limit, entry.max$, on the length of an entry string variable
  2414. % (which is what its sort.key$ is), so we take at most that many characters
  2415. % of the constructed key, and hope there aren't many references that match
  2416. % to that many characters!
  2417.  
  2418. FUNCTION {presort}
  2419. #if LAB_ALPH
  2420. { calc.label
  2421.   sort.label
  2422.   "    "
  2423.   *
  2424.   type$ "book" =
  2425. #else !LAB_ALPH
  2426. { type$ "book" =
  2427. #endif LAB_ALPH
  2428.   type$ "inbook" =
  2429.   or
  2430.     'author.editor.sort
  2431.     { type$ "proceedings" =
  2432.         'editor.organization.sort
  2433.         { type$ "manual" =
  2434.             'author.organization.sort
  2435.             'author.sort
  2436.           if$
  2437.         }
  2438.       if$
  2439.     }
  2440.   if$
  2441. #if LAB_ALPH
  2442.   *
  2443. #endif LAB_ALPH
  2444.   "    "
  2445.   *
  2446.   year field.or.null sortify
  2447.   *
  2448.   "    "
  2449.   *
  2450.   title field.or.null
  2451.   sort.format.title
  2452.   *
  2453.   #1 entry.max$ substring$
  2454.   'sort.key$ :=
  2455. }
  2456.  
  2457. ITERATE {presort}
  2458.  
  2459. % And now we can sort
  2460.  
  2461. SORT
  2462.  
  2463. #endif SORTED
  2464.  
  2465. % This long comment applies only to alphabetic labels, when sorted
  2466. %
  2467. % Now comes the final computation for alphabetic labels, putting in the 'a's
  2468. % and 'b's and so forth if required.  This involves two passes: a forward
  2469. % pass to put in the 'b's, 'c's and so on, and a backwards pass
  2470. % to put in the 'a's (we don't want to put in 'a's unless we know there
  2471. % are 'b's).
  2472. % We have to keep track of the longest (in width$ terms) label, for use
  2473. % by the "thebibliography" environment.
  2474. %
  2475. % VAR: longest.label, last.sort.label, next.extra: string
  2476. %      longest.label.width, last.extra.num: integer
  2477. %
  2478. % initialize.longest.label ==
  2479. %  BEGIN
  2480. %       longest.label := ""
  2481. %       last.sort.label := int.to.chr$(0)
  2482. %       next.extra := ""
  2483. %       longest.label.width := 0
  2484. %       last.extra.num := 0
  2485. %  END
  2486. %
  2487. % forward.pass ==
  2488. %  BEGIN
  2489. %       if last.sort.label = sort.label then
  2490. %           last.extra.num := last.extra.num + 1
  2491. %           extra.label := int.to.chr$(last.extra.num)
  2492. %       else
  2493. %           last.extra.num := chr.to.int$("a")
  2494. %           extra.label := ""
  2495. %           last.sort.label := sort.label
  2496. %       fi
  2497. %  END
  2498. %
  2499. % reverse.pass ==
  2500. %  BEGIN
  2501. %       if next.extra = "b" then
  2502. %           extra.label := "a"
  2503. %       fi
  2504. %       label := label * extra.label
  2505. %       if width$(label) > longest.label.width then
  2506. %           longest.label := label
  2507. %           longest.label.width := width$(label)
  2508. %       fi
  2509. %       next.extra := extra.label
  2510. %  END
  2511.  
  2512. #if LAB_ALPH
  2513.  
  2514. #if SORTED
  2515.  
  2516. STRINGS { longest.label last.sort.label next.extra }
  2517.  
  2518. INTEGERS { longest.label.width last.extra.num }
  2519.  
  2520. FUNCTION {initialize.longest.label}
  2521. { "" 'longest.label :=
  2522.   #0 int.to.chr$ 'last.sort.label :=
  2523.   "" 'next.extra :=
  2524.   #0 'longest.label.width :=
  2525.   #0 'last.extra.num :=
  2526. }
  2527.  
  2528. FUNCTION {forward.pass}
  2529. { last.sort.label sort.label =
  2530.     { last.extra.num #1 + 'last.extra.num :=
  2531.       last.extra.num int.to.chr$ 'extra.label :=
  2532.     }
  2533.     { "a" chr.to.int$ 'last.extra.num :=
  2534.       "" 'extra.label :=
  2535.       sort.label 'last.sort.label :=
  2536.     }
  2537.   if$
  2538. }
  2539.  
  2540. FUNCTION {reverse.pass}
  2541. { next.extra "b" =
  2542.     { "a" 'extra.label := }
  2543.     'skip$
  2544.   if$
  2545.   label extra.label * 'label :=
  2546.   label width$ longest.label.width >
  2547.     { label 'longest.label :=
  2548.       label width$ 'longest.label.width :=
  2549.     }
  2550.     'skip$
  2551.   if$
  2552.   extra.label 'next.extra :=
  2553. }
  2554.  
  2555. EXECUTE {initialize.longest.label}
  2556.  
  2557. ITERATE {forward.pass}
  2558.  
  2559. REVERSE {reverse.pass}
  2560.  
  2561. #else !SORTED
  2562.  
  2563. % It still doesn't seem like a good idea to use an order-of-citation
  2564. % reference list when using alphabetic labels, but when this happens we
  2565. % must compute the longest label
  2566.  
  2567. STRINGS { longest.label }
  2568.  
  2569. INTEGERS { longest.label.width }
  2570.  
  2571. FUNCTION {initialize.longest.label}
  2572. { "" 'longest.label :=
  2573.   #0 'longest.label.width :=
  2574. }
  2575.  
  2576. FUNCTION {longest.label.pass}
  2577. { label width$ longest.label.width >
  2578.     { label 'longest.label :=
  2579.       label width$ 'longest.label.width :=
  2580.     }
  2581.     'skip$
  2582.   if$
  2583. }
  2584.  
  2585. EXECUTE {initialize.longest.label}
  2586.  
  2587. ITERATE {longest.label.pass}
  2588.  
  2589. #endif SORTED
  2590.  
  2591. #else !LAB_ALPH
  2592.  
  2593. % Now comes the computation for numeric labels.
  2594. % We use either the sorted order or original order.
  2595. % We still have to keep track of the longest (in width$ terms) label, for use
  2596. % by the "thebibliography" environment.
  2597.  
  2598. STRINGS { longest.label }
  2599.  
  2600. INTEGERS { number.label longest.label.width }
  2601.  
  2602. FUNCTION {initialize.longest.label}
  2603. { "" 'longest.label :=
  2604.   #1 'number.label :=
  2605.   #0 'longest.label.width :=
  2606. }
  2607.  
  2608. FUNCTION {longest.label.pass}
  2609. { number.label int.to.str$ 'label :=
  2610.   number.label #1 + 'number.label :=
  2611.   label width$ longest.label.width >
  2612.     { label 'longest.label :=
  2613.       label width$ 'longest.label.width :=
  2614.     }
  2615.     'skip$
  2616.   if$
  2617. }
  2618.  
  2619. EXECUTE {initialize.longest.label}
  2620.  
  2621. ITERATE {longest.label.pass}
  2622.  
  2623. #endif LAB_ALPH
  2624.  
  2625. % Now we're ready to start writing the .BBL file.
  2626. % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
  2627. % label; next comes stuff from the `preamble' command in the database files.
  2628. % Then we give an incantation containing the command
  2629. %     \begin{thebibliography}{...}
  2630. % where the `...' is the longest label.
  2631. %
  2632. % We also call init.state.consts, for use by the output routines.
  2633.  
  2634. FUNCTION {begin.bib}
  2635. #if LAB_ALPH
  2636. { et.al.char.used
  2637.     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
  2638.     'skip$
  2639.   if$
  2640.   preamble$ empty$
  2641. #else !LAB_ALPH
  2642. { preamble$ empty$
  2643. #endif LAB_ALPH
  2644.     'skip$
  2645.     { preamble$ write$ newline$ }
  2646.   if$
  2647.   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
  2648. }
  2649.  
  2650. EXECUTE {begin.bib}
  2651.  
  2652. EXECUTE {init.state.consts}
  2653.  
  2654. % Now we produce the output for all the entries
  2655.  
  2656. ITERATE {call.type$}
  2657.  
  2658. % Finally, we finish up by writing the `\end{thebibliography}' command.
  2659.  
  2660. FUNCTION {end.bib}
  2661. { newline$
  2662.   "\end{thebibliography}" write$ newline$
  2663. }
  2664.  
  2665. EXECUTE {end.bib}
  2666.